<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>表单页面</title>
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />

    <style>
        .uploadSource_img{
            width:120px;
        }
        .uploadSource_img1{
            height:120px;
            width:70px;
        }
        .uploadSource_img1 {
   
            line-height: 120px;
            margin-right: 10px;
            border: 1px dashed #ededed;
            text-align: center;
            color: #dad9d9;
            position: relative;
            cursor: pointer;
            background: white;
        }
        .bkClass{
            background-color: #000!important;
        }
   
    </style>
</head>

<body>
    <form class="layui-form" action="" id="formId">
        <div class="mainBox">
            <div class="main-container">
                
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" value="{$msg.title|default=''}" lay-verify="required"
                            autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                {if $Request.get.type!=2}
                <div class="layui-form-item">
                    <label class="layui-form-label">头图</label>
                    <div class="layui-input-block">

                        <div class="clearfix">
                            <div class="clearfix pull-left"></div>
                            {if $Request.get.type==0}
                                <div class="uploadSource_img" onclick="uploadImg(this)">
                                    {if empty($msg.img)}
                                    <i class="pear-icon pear-icon-add-bold" style="font-size: 30px;"></i>
                                    {else/} 
                                    <img src="/static/files/runtimefile/{$msg.img}" style="width:120px;height:60px;">
                                    {/if}
                                </div>
                            {elseif $Request.get.type==1}
                                <div class="uploadSource_img1" onclick="uploadImg(this)">
                                    {if empty($msg.img)}
                                    <i class="pear-icon pear-icon-add-bold" style="font-size: 30px;"></i>
                                    {else/} 
                                    <img src="/static/files/runtimefile/{$msg.img}" style="width:70px;height:120px;">
                                    {/if}
                                </div>
                            {/if}

                            <input type="file" class="fileUpdate_attrClass" name="img" style="display:none;" id="fileId">
                        </div>
                    </div>
                </div>
                {/if}
                <div class="layui-form-item">
                    <label class="layui-form-label">内容</label>
                    <div class="layui-input-block">
                        <script id="rw_describeId" type="text/plain" style="height: 300px;" name="content" >{$msg.content|raw}</script>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        {php}
                            $status = empty($msg['status']) ? 0 : 1;
                        {/php}
                        <input type="checkbox"  value="1" lay-skin="switch" lay-text="已开启|已停用"  lay-filter="status-set" {if $status}  checked {/if} />
                        <input type="hidden" id="statusIds" value="{$status}" name="status">
                        <input type="hidden" name="type" value="{$Request.get.type}">
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="form-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
    <script src="/static/user/js/jquery.min.js"></script>
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
    <script type="text/javascript" charset="utf-8" src="/static/editor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/static/editor/ueditor.all.js"> </script>
    <script type="text/javascript" charset="utf-8" src="/static/editor/lang/zh-cn/zh-cn.js"></script>
    <script>
   
        var ue = UE.getEditor('rw_describeId');
   


        layui.use(['form', 'jquery','drawer'], function () {
            let form = layui.form;
            let drawer=layui.drawer;
            let $ = layui.jquery;

            form.on('switch(status-set)', function (obj) {
                    var id= this.value;
                    var status= obj.elem.checked ? 1 :0 ;
                    $("#statusIds").val(status);
                });
           


            form.on('submit(form-save)', function (data) {
                //var data = data.field ;//JSON.stringify(data.field);
                var data = $("#formId");
                var url = "{:url('article/artSave')}?id={$Request.get.id}";
                
                postDatai(url, data).then(function (res) {
                    if (res.code == 200) {
                        layer.msg(res.message, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("tableId");
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 2,
                            time: 1000
                        });
                    }
                });
                return false;
            });





        })
        // 规格图上传

        function uploadImg(item) {
            $(item).next(".fileUpdate_attrClass").click();
        };
        $("body").on("change", ".fileUpdate_attrClass", function () {
            if ($(this).val()) {

                var imgurl = getObjectURL(this.files[0]);
                "{if $Request.get.type==0}"
                    $(this).prev(".uploadSource_img").html(`<img src="${imgurl}" style="width:120px;height:60px;">`);
                "{elseif $Request.get.type==1}"
                    $(this).prev(".uploadSource_img1").html(`<img src="${imgurl}" style="width:70px;height:120px;">`);
                "{/if}"
            }
        });
    </script>
    <script>
        //c2inputId  SelectStatusid  SelectEId  //hrefdivId

        //--提供子窗口调用的方法
        function CallParent(id,title){
            $("#c2inputId").val(id);
            $("#SelectEId").html("已选中|"+title);
            layer.close(_r_drawer) 
        }
  


    </script>

    {include file="base/unitjs"}
</body>

</html>